<?php
class announcements_edit extends SClass {

    public function process() {
    	try {
    		$announcement = ServiceUtils::GetFactory()->getAnnouncementService()->getAnnouncementById(
    			$this->getArgument('id')
    		);
    		if ($this->getControlValue('save')) {
    			ServiceUtils::GetFactory()->getAnnouncementService()->editAnnouncement(
    				$announcement->getId(),
    				$this->getControlValue('title'),
    				$this->getControlValue('preview'),
    				$this->getControlValue('content')
    			);
    			$this->assign('message', 'ok');
    		} else {
    			$this->setControlValue('title', $announcement->getTitle());
    			$this->setControlValue('preview', $announcement->getPreview());
    			$this->setControlValue('content', $announcement->getContent());
    		}
    	} catch (ServiceUtils_Exception $exception) {
    		$this->assign('errors', $exception->getErrors());
    	}
    }

}